﻿#region license
//Copyright 2008 Ritesh Rao 

//Licensed under the Apache License, Version 2.0 (the "License"); 
//you may not use this file except in compliance with the License. 
//You may obtain a copy of the License at 

//http://www.apache.org/licenses/LICENSE-2.0 

//Unless required by applicable law or agreed to in writing, software 
//distributed under the License is distributed on an "AS IS" BASIS, 
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
//See the License for the specific language governing permissions and 
//limitations under the License. 
#endregion

using System;
using NCommon;

namespace Rhinestone.Domain
{
    /// <summary>
    /// A comment entry associated with a <see cref="WorkItem"/> instance.
    /// </summary>
    public class Comment
    {
        #region fields
        private int _commentID;
        private DateTime _created;
        private DateTime _modified;
        private WorkItem _workItem;
        private IUser _createdBy;
        #endregion

        #region .ctor
        /// <summary>
        /// Inherited constructor.
        /// </summary>
        protected Comment () {}

        /// <summary>
        /// Default Constructor.
        /// Creates a new instance of the <see cref="Comment"/> class.
        /// </summary>
        /// <param name="user">A <see cref="IUser"/> instance representing the user
        /// who is creating this comment.</param>
        public Comment(IUser user)
        {
            Guard.Against<ArgumentNullException>(user == null, "Please provide a valid non-null instance for user. Null IUser instance found in user.");
            DateTime now = DateTime.Now;
            _createdBy = user;
            _created = now;
            _modified = now;
        }
        #endregion

        #region properties
        /// <summary>
        /// Gets the unique ID assigned to the comment.
        /// </summary>
        /// <value>int. The unique ID assigned to the comment.</value>
        public virtual int CommentID
        {
            get
            {
                return _commentID;
            }
        }

        /// <summary>
        /// Gets the date and time the comment was created.
        /// </summary>
        /// <value>DateTime. The date and time the comment was created.</value>
        public virtual DateTime Created
        {
            get
            {
                return _created;
            }
        }

        /// <summary>
        /// Gets the date and time the comment was last modified.
        /// </summary>
        /// <value>DateTime. The date and time the comment was last modified.</value>
        public virtual DateTime Modified
        {
            get { return _modified; }
        }

        /// <summary>
        /// Gets or sets the title of the comment.
        /// </summary>
        /// <value>string. The title of the comment.</value>
        public virtual string Title { get; set; }

        /// <summary>
        /// Gets or sets the description of the comment.
        /// </summary>
        /// <value>string. The description of the comment.</value>
        public virtual string Description { get; set; }

        /// <summary>
        /// Gets the <see cref="WorkItem"/> instance the comment is associated with.
        /// </summary>
        /// <value>The <see cref="WorkItem"/> instance the comment is associated with.</value>
        public virtual WorkItem WorkItem
        {
            get { return _workItem; }
            internal set { _workItem = value; }
        }

        /// <summary>
        /// Gets the <see cref="IUser"/> that created this comment.
        /// </summary>
        /// <value>An <see cref="IUser"/> instance representing the user that created this comment.</value>
        public virtual IUser CreatedBy
        {
            get { return _createdBy; }
        } 
        #endregion
    }
}
